﻿using System;
using System.Collections.Generic;
using UILib;
using UnityEngine;
using XUtliPoolLib;

namespace XMainClient.UI
{
	// Token: 0x020017D0 RID: 6096
	internal class XNpcAttrHandler : DlgHandlerBase
	{
		// Token: 0x170038A2 RID: 14498
		// (get) Token: 0x0600FC87 RID: 64647 RVA: 0x003AEB60 File Offset: 0x003ACD60
		protected override string FileName
		{
			get
			{
				return "GameSystem/NPCBlessing/NpcAttrHandler";
			}
		}

		// Token: 0x0600FC88 RID: 64648 RVA: 0x003AEB78 File Offset: 0x003ACD78
		protected override void Init()
		{
			base.Init();
			this.m_doc = XDocuments.GetSpecificDocument<XNPCFavorDocument>(XNPCFavorDocument.uuID);
			this.m_BasicUIList = (base.transform.Find("AttrGrid").GetComponent("XUIList") as IXUIList);
			Transform transform = this.m_BasicUIList.gameObject.transform.Find("Tpl");
			this.m_BasicAttrPool.SetupPool(this.m_BasicUIList.gameObject, transform.gameObject, 10U, false);
			transform.gameObject.SetActive(false);
			this.m_OtherUIList = (base.transform.Find("NoBasicAttrGrid").GetComponent("XUIList") as IXUIList);
			Transform transform2 = this.m_OtherUIList.gameObject.transform.Find("Tpl");
			this.m_OtherAttrPool.SetupPool(this.m_OtherUIList.gameObject, transform2.gameObject, 5U, false);
			transform2.gameObject.SetActive(false);
		}

		// Token: 0x0600FC89 RID: 64649 RVA: 0x001A787A File Offset: 0x001A5A7A
		protected override void OnShow()
		{
			this.RefreshData();
		}

		// Token: 0x0600FC8A RID: 64650 RVA: 0x003AEC76 File Offset: 0x003ACE76
		public override void RefreshData()
		{
			this.RefreshAttr();
		}

		// Token: 0x0600FC8B RID: 64651 RVA: 0x003AEC80 File Offset: 0x003ACE80
		private void RefreshAttr()
		{
			this.m_BasicAttrPool.FakeReturnAll();
			this.m_OtherAttrPool.FakeReturnAll();
			Dictionary<uint, uint> dictSumAttr = this.m_doc.DictSumAttr;
			foreach (KeyValuePair<uint, uint> keyValuePair in dictSumAttr)
			{
				uint key = keyValuePair.Key;
// 				Dictionary<uint, uint>.Enumerator enumerator;
// 				keyValuePair = enumerator.Current;
				uint value = keyValuePair.Value;
				bool flag = XAttributeCommon.IsBasicRange((int)key);
				GameObject gameObject;
				if (flag)
				{
					gameObject = this.m_BasicAttrPool.FetchGameObject(false);
					gameObject.transform.parent = this.m_BasicUIList.gameObject.transform;
				}
				else
				{
					gameObject = this.m_OtherAttrPool.FetchGameObject(false);
					gameObject.transform.parent = this.m_OtherUIList.gameObject.transform;
				}
				gameObject.transform.localScale = Vector3.one;
				this.DrawAttr(gameObject.transform, key, value);
			}
			this.m_BasicAttrPool.ActualReturnAll(false);
			this.m_OtherAttrPool.ActualReturnAll(false);
			this.m_BasicUIList.Refresh();
			this.m_OtherUIList.Refresh();
		}

		// Token: 0x0600FC8C RID: 64652 RVA: 0x003AEDAA File Offset: 0x003ACFAA
		public override void OnUnload()
		{
			this.m_doc = null;
			base.OnUnload();
		}

		// Token: 0x0600FC8D RID: 64653 RVA: 0x003AEDBC File Offset: 0x003ACFBC
		private void DrawAttr(Transform item, uint attrId, uint attrValue)
		{
			IXUILabel ixuilabel = item.Find("Name").GetComponent("XUILabel") as IXUILabel;
			IXUILabel ixuilabel2 = item.Find("Value").GetComponent("XUILabel") as IXUILabel;
			ixuilabel.SetText(XAttributeCommon.GetAttrStr((int)attrId));
			ixuilabel2.SetText(XAttributeCommon.GetAttrValueStr(attrId, attrValue, true));
		}

		// Token: 0x04006EFE RID: 28414
		private XNPCFavorDocument m_doc;

		// Token: 0x04006EFF RID: 28415
		private IXUIList m_BasicUIList;

		// Token: 0x04006F00 RID: 28416
		private XUIPool m_BasicAttrPool = new XUIPool(XSingleton<XGameUI>.singleton.m_uiTool);

		// Token: 0x04006F01 RID: 28417
		private IXUIList m_OtherUIList;

		// Token: 0x04006F02 RID: 28418
		private XUIPool m_OtherAttrPool = new XUIPool(XSingleton<XGameUI>.singleton.m_uiTool);
	}
}
